package com.iceph0x.android.aidl;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author ywang
 */
public class Person implements Parcelable {

    private String name;
    private int age;
    private String sex;
    
    
    public Person() { }
    
    public Person(Parcel p) {
        name = p.readString();
        sex = p.readString();
        age = p.readInt();
    }
    
    public static Person born() {
        Person person = new Person();
        person.name = "xx";
        person.age = (int) System.currentTimeMillis() % 100;
        person.sex = (person.age & 1) == 0 ? "female" : "male";
        return person;
    }
    
    @Override
    public String toString() {
        return name + " " + sex + " " + age;
    }
    
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel arg0, int arg1) {
        arg0.writeString(name);
        arg0.writeString(sex);
        arg0.writeInt(age);
    }
    
    public static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {
        @Override
        public Person createFromParcel(Parcel source) {
            return new Person(source);
        }

        @Override
        public Person[] newArray(int size) {
            return new Person[size];
        }
    };
}
